package com.youhong.teethcare.customviews;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.youhong.teethcare.R;

/**
 * Created by Administrator on 2018/4/28 0028.
 */

public class MyProgress extends View {

    public MyProgress(Context context) {
        super(context);
    }

    public MyProgress(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.MyProgressBar);

        borderColor = ta.getColor(R.styleable.MyProgressBar_myProgressbar_borderColor, Color.parseColor("#40c4ff"));
        progress = ta.getColor(R.styleable.MyProgressBar_progressColor, Color.parseColor("#40c4ff"));
        progress = ta.getColor(R.styleable.MyProgressBar_progressColor, Color.parseColor("#40c4ff"));
        borderWidth = ta.getDimension(R.styleable.MyProgressBar_myProgressBar_borderWidth, 5f);

    }

    public MyProgress(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.MyProgressBar);

        borderColor = ta.getColor(R.styleable.MyProgressBar_myProgressbar_borderColor, Color.parseColor("#40c4ff"));
        progress = ta.getColor(R.styleable.MyProgressBar_progressColor, Color.parseColor("#40c4ff"));
        borderWidth = ta.getDimension(R.styleable.MyProgressBar_myProgressBar_borderWidth, 5f);

    }

    int borderColor, progressColor;
    float borderWidth;

    float width, height;
    RectF rectf;

    Paint paint_text = new Paint();
    Paint paint_circle = new Paint();

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        width = w;
        height = h;
        rectf = new RectF(0, 0, w, h);
        paint_text.setAntiAlias(true);
        paint_text.setColor(Color.parseColor("#0088D5"));
        paint_text.setTextSize(36f);

        paint_circle.setAntiAlias(true);
        paint_circle.setColor(Color.parseColor("#05A0FF"));
        paint_circle.setStrokeWidth(borderWidth);

    }

    public void setProgress(int progress) {
        this.progress = progress;
    }

    int progress;

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        //画外框
        paint_circle.setStyle(Paint.Style.STROKE);
        paint_circle.setColor(borderColor);
        canvas.drawRoundRect(rectf, 0, 0, paint_circle);

        //画进度
        paint_circle.setStyle(Paint.Style.FILL);
        paint_circle.setColor(progressColor);

    }

}

